package com.kaede.hayate.security.entity;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.StringUtils;

public class RestGrantedAuthority implements GrantedAuthority {

	private static final long serialVersionUID = 1L;

	private Long id;
	private String url;
	private String method;
	private String authority;

	public RestGrantedAuthority() {
	}

	public RestGrantedAuthority(Long id, String url, String method) {
		this.id = id;
		this.url = url;
		this.method = method;
		this.authority = url + ":" + method;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getMethod() {
		return method;
	}

	public void setMethod(String method) {
		this.method = method;
	}

	public void setAuthority(String authority) {
		this.authority = authority;
	}

	@Override
	public String getAuthority() {
		return StringUtils.isEmpty(authority) ? url + ":" + method : authority;
	}

}
